<?
/**
 * ajax 头文件,与common.inc.php功能差不多，只是有些功能在AJAX里用不到的去掉了，以节省资源
 * 
 * @copyright Copyright (c) 2008 sdmblog (http://www.sdmblog.cn)
 * @author sdomain(sdomain@live.cn)
 * @version ajax.common.php Sat May 17 17:07:20 CST 2008 php $
 */
define('SDOMAIN', TRUE);
define('ROOT_PATH', substr(dirname(__FILE__), 0, -7));
$virname = substr($_SERVER['SCRIPT_NAME'],0,strrpos($_SERVER['SCRIPT_NAME'],'/')+1);
//尝试获取客户端IP
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
	$ip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
	$ip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
	$ip = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
	$ip = $_SERVER['REMOTE_ADDR'];
}
// 如果成功匹配IP(7-15个由数字和点组成的字符), 同时过滤一些不明物
preg_match("/[\d\.]{7,15}/", $ip, $ipmatches);
// 上面$ipmatches[0]如果没有取得IP就赋值unknown
$ip = $ipmatches[0] ? $ipmatches[0] : 'unknown';
unset($ipmatches);
//处理不用变量
unset($HTTP_ENV_VARS, $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_POST_FILES, $HTTP_COOKIE_VARS, $dbhost, $dbuser, $dbpwd, $dbname, $tablepre);


//加载必要文件
require_once ROOT_PATH .'./include/config.inc.php';
require_once ROOT_PATH .'./include/mysql.cls.php';
require_once ROOT_PATH .'./include/func.lib.php';
//数据库连接
$db = new DB_CLASS;
$db->connect($dbconfig);

//系统配置缓存文件
//此文件是可以删除的,删除后会自动重建
if (!file_exists(ROOT_PATH.'./'.$cachepath.'config/webconfig.php')) {
	if (!loadConfig()) {
		exit('加载配置文件出错,请检查文件夹的读写权限');	
	}
}
require_once ROOT_PATH.'./'.$cachepath.'config/webconfig.php';

require_once ROOT_PATH .'./languages/'.$cfg_bloglanguage.'.php';

$vmodel = $_COOKIE[$cookiepre.'vmodel'];
//显示模式：normal或list 如果COOKIE里有,则从COOKIE里取,否则为默认
$vmodel=$vmodel?$vmodel:$cfg_viewmodel;
//网站状态
$webstate = GP("webstate");
?>